package com.example.chenjun.myapplication.util;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class TypeUtil {

    public static Type getType(Object obj){
        return getType(obj, 0);
    }

    public static Type getType(Object obj, int index){
        Type type = obj.getClass().getGenericSuperclass();
        if (type instanceof ParameterizedType){
            return ((ParameterizedType) type).getActualTypeArguments()[index];
        }
        return null;
    }
}
